/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.me.utils;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import java.util.Date;
import java.util.GregorianCalendar;
import org.me.schedule.Calendar;
import org.me.schedule.Day;

/**
 *
 * @author peterholtegaard@gmail.com
 */
public class CalendarReader extends Thread {
    //private String userName;
    //private String passWord;

    private GregorianCalendar startDay;
    private GregorianCalendar endDay;
    final Handler mHandler;

    public CalendarReader(Handler h) {
        mHandler = h;
    }

    public void setStartDay(GregorianCalendar startDay) {
        this.startDay = startDay;
    }

    public void setEndDate(GregorianCalendar endDay) {
        this.endDay = endDay;
    }

    public Calendar getTTVCalendar() {


        NetworkDataProvider comm = NetworkDataProvider.getInstance();
        comm.logIn();
        Calendar cal = new Calendar();
        Message msg = null;
        Bundle b = null;
        Date dato = new Date();

        int date = dato.getDate();
        while (date < 30) {
            int year = dato.getYear() + 1900;
            int month = dato.getMonth() + 1;
            String tjek = comm.getDayAsHtml(year, month, date);
            Day d = Day.getSpecifiedDay(tjek);
            b = new Bundle();
            msg = mHandler.obtainMessage();
            b.putCharSequence("day", d.toString());
            msg.setData(b);
            mHandler.sendMessage(msg);
            date++;
        }

        return cal;

    }

    @Override
    public void run() {
        Looper.prepare();
        getTTVCalendar();
    }

    public Day getTTVDay(Date date) {
        return null;
    }
}
